package observer.javaobserver;

import observer.CurrentConditionDisplay;
import observer.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by lenovo on 2017/11/7.
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
    Observable observable;
    private float temperature;
    private float humidity;

    public CurrentConditionsDisplay(Observable observable){
        this.observable=observable;
        observable.addObserver(this);
    }
    @Override
    public void update(Observable obs, Object arg) {
        if(obs instanceof  WeatherData){

            WeatherData weatherData= (WeatherData) obs;
            this.temperature=weatherData.getTemperature();
            this.humidity=weatherData.getHumidity();
            dispaly();
        }


    }

    @Override
    public void dispaly() {

        System.out.println("current conditions:"+temperature+" f degrees and "+humidity);
    }
}
